using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using LeisureCenter.Api;
using LeisureCenter.Core;

namespace LeisureCenter.MenuItems
{
    public class ExternalApplicationMenuItem : IMenuItem
    {
        private ExternalApplication app;

        public ExternalApplicationMenuItem(ExternalApplication app)
        {
            this.app = app;
        }

        #region IMenuItem Membres

        public string Text { get { return this.app.Name; } }

        public string IconName
        {
            get
            {
                Program.LeisureCenterInstance.IconsManager.AddToImageLists(this.app.IconPath);
                return this.app.IconPath;
            }
        }

        public void Execute()
        {
            ExecuteAgain();
        }

        public void ExecuteAgain()
        {
            Process.Start(this.app.Path);
        }

        public void OptionsExecute()
        {
        }

        #endregion
    }

    public class ExternalApplicationsMainMenuItem : IMenuItem
    {
        List<IMenuItem> items;

        #region IMenuItem Membres

        public string Text { get { return @"External Applications"; } }

        public string IconName { get { return @"ExternalApplications"; } }

        public void Execute()
        {
            ExecuteAgain();
        }

        public void ExecuteAgain()
        {
            if (this.items == null)
            {
                this.items = new List<IMenuItem>();
                foreach (ExternalApplication app in Program.LeisureCenterInstance.Settings.ExternalApplications)
                {
                    this.items.Add(new ExternalApplicationMenuItem(app));
                }
            }
            Program.LeisureCenterInstance.MenuManager.FillSubmenu(this.items);
        }

        public void OptionsExecute()
        {
        }

        #endregion
    }

    public class ExternalApplicationsMainMenuItemsProvider : IMainMenuItemsProvider
    {
        private List<IMenuItem> items;

        #region IMainMenuItemsProvider Membres

        public IEnumerable<IMenuItem> Items
        {
            get 
            {
                if (this.items == null)
                {
                    this.items = new List<IMenuItem>();
                    if (Program.LeisureCenterInstance.Settings.ExternalApplications.Count > 0)
                        this.items.Add(new ExternalApplicationsMainMenuItem());
                }
                return this.items;
            }
        }

        #endregion
    }
}